<!--
 * @Descripttion: 全部订单
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2021-10-20 14:11:17
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-12 16:36:51
-->
<template>
  <div>
    <div class="table-content" v-for="(item, index) in orderData" :key="index">
      <div class="header">
        <span style="font-weight: 700">{{ item.createTime }}</span>
        <span style="margin-left: 20px">订单号：{{ item.orderNumber }}</span>
      </div>
      <div class="content">
        <div class="content-order active">
          <div class="ac-img">
            <img :src="item.orderTypeImg" alt="" />
          </div>
          <div>
            <div>
              <div
                class="ac-jt"
                style="
                  font-size: 14px;
                  font-family: PingFangSC-Medium, PingFang SC;
                  font-weight: 500;
                  color: #2b2b2b;
                "
              >
                {{ item.batchName }}
              </div>
              <div
                class="ac-jt"
                style="
                  font-size: 12px;
                  font-family: PingFangSC-Regular, PingFang SC;
                  font-weight: 400;
                  color: #666666;
                "
              >
                {{ item.total }}/人
              </div>
            </div>
          </div>
        </div>
        <div class="content-order">{{ item.total }}</div>
        <div class="content-order">{{ item.paymentType | payType }}</div>
        <div class="content-order">
          <el-button type="primary" size="default" @click="Issue(item)">
            开具发票
          </el-button>
        </div>
      </div>
    </div>
    <el-dialog
      title="填写开票信息"
      :visible.sync="IssueShow"
      width="50%"
      @close="IssueClose"
    >
      <div class="invoiceType">
        <div>
          <el-form
            :model="typeForm"
            ref="typeForm"
            :rules="typeRules"
            label-position="top"
          >
            <el-form-item label="发票类型" prop="type">
              <div class="typeItem">
                <div class="typeItem-Iss">
                  <div
                    class="typeIss"
                    :class="typeForm.type == 1 ? 'activeIss' : ''"
                    @click="typeIssTog"
                  >
                    <div class="typeIss-up">增值税普通发票（电子发票）</div>
                    <div class="typeIss-down">
                      电子发票与纸质发票具备同等法律效力，推荐开具
                    </div>
                  </div>
                </div>
                <div class="typeItem-Iss">
                  <div
                    class="typeIss"
                    :class="typeForm.type == 2 ? 'activeIss' : ''"
                    @click="typeIssTogg"
                  >
                    <div class="typeIss-up">增值税专用发票（纸质发票）</div>
                    <div class="typeIss-down">
                      开具纸质发票需要承担运费，运费为到付
                    </div>
                  </div>
                </div>
              </div>
            </el-form-item>
          </el-form>
        </div>
        <div class="ordinary" v-if="typeForm.type == 1">
          <ele-invoice
            :ordinaryForm="ordinaryForm"
            :IssueShow="IssueShow"
            ref="Issue"
          ></ele-invoice>
        </div>
        <div class="purpose" v-if="typeForm.type == 2">
          <paper
            :IssueShow="IssueShow"
            :ordinaryForm="ordinaryForm"
            ref="ordinary"
          ></paper>
        </div>
      </div>
      <span slot="footer">
        <el-button @click="IssueShow = false">取消</el-button>
        <el-button type="primary" @click="onSubmit"> 提交 </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { applyInvoice, checkInvoice } from "@/api/invoiceAst.js";
import eleInvoice from "./allOrder/eleInvoice.vue";
import Paper from "./allOrder/paper.vue";
export default {
  components: { eleInvoice, Paper },
  props: {
    orderData: {
      type: Array,
      required: true,
    },
  },
  filters: {
    payType: function (val) {
      if (val == 1) {
        val = "微信";
      } else if (val == 2) {
        val = "支付宝";
      } else if (val == 3) {
        val = "线下支付";
      }
      return val;
    },
    statusType: function (val) {
      if (val == 1) {
        val = "待支付";
      } else if (val == 2) {
        val = "已支付";
      } else if (val == 3) {
        val = "已取消";
      }
      return val;
    },
  },
  data() {
    return {
      orderNumber: "",
      orgId: "",
      ordinaryForm: {
        invoiceType: 1,
        orderNumber: "",
        orgId: "",
        titleType: "",
        title: "",
        taxNumber: "",
        content: "",
        remark: "",
        email: "",
        vatId: "",
        addressId: "",
      },
      IssueShow: false,
      typeForm: {
        type: 1,
      },
      typeRules: {
        type: [
          {
            required: true,
          },
        ],
      },
    };
  },
  methods: {
    IssueClose() {
      this.ordinaryForm = {
        invoiceType: "",
        orderNumber: "",
        orgId: "",
        titleType: "",
        title: "",
        taxNumber: "",
        content: "",
        remark: "",
        email: "",
        vatId: "",
        addressId: "",
      };
      this.typeForm.type = 1;
    },
    // 开具发票
    onSubmit() {
      if (this.typeForm.type == 1) {
        this.$refs.Issue.$refs.ordinaryForm.validate((valid) => {
          if (!valid) return;
          applyInvoice(this.ordinaryForm).then((res) => {
            this.IssueShow = false;
            this.$message.success(res.msg);
            this.$parent.getList();
          });
        });
      } else if (this.typeForm.type == 2) {
        if (this.ordinaryForm.addressId == "") {
          return this.$message.info("请选择或者添加地址信息");
        }
        if (this.ordinaryForm.vatId == "") {
          return this.$message.info("请选择或者添加发票信息");
        }
        this.$refs.ordinary.$refs.ordinaryForm.validate((valid) => {
          if (!valid) return;
          applyInvoice(this.ordinaryForm).then((res) => {
            this.IssueShow = false;
            this.$message.success(res.msg);
            this.$parent.getList();
          });
        });
      }
    },

    // 电子发票
    typeIssTog() {
      this.ordinaryForm = {
        invoiceType: "",
        orderNumber: this.orderNumber,
        orgId: this.orgId,
        titleType: "",
        title: "",
        taxNumber: "",
        content: "",
        remark: "",
        email: "",
        vatId: "",
        addressId: "",
      };
      this.typeForm.type = 1;
      this.ordinaryForm.invoiceType = 1;
    },
    typeIssTogg() {
      this.ordinaryForm = {
        invoiceType: "",
        orderNumber: this.orderNumber,
        orgId: this.orgId,
        titleType: "",
        title: "",
        taxNumber: "",
        content: "",
        remark: "",
        email: "",
        vatId: "",
        addressId: "",
      };
      this.typeForm.type = 2;
      this.ordinaryForm.invoiceType = 2;
    },
    Issue(item) {
      checkInvoice({
        orderNumber: item.orderNumber,
      }).then((res) => {
        this.IssueShow = true;
        this.ordinaryForm.orgId = item.orgId;
        this.ordinaryForm.orderNumber = item.orderNumber;
        this.orderNumber = item.orderNumber;
        this.orgId = item.orgId;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.table-content {
  border: 1px solid #dfe5ea;
  margin-top: 10px;
  width: 100%;
  height: 198px;
  .header {
    padding-left: 20px;
    width: 100%;
    height: 55px;
    line-height: 55px;
    font-size: 14px;
    background-color: #f8fafc;
  }
  .content {
    width: 100%;
    height: 144px;
    // line-height: 144px;
    align-items: center;
    display: flex;
    justify-content: space-around;
    .content-order {
      width: 20%;
      text-align: center;
    }
  }
}
.active {
  display: flex;
  align-items: center;
  justify-content: center;
  .ac-img {
    width: 86px;
    height: 86px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .ac-jt {
    margin-left: 26px;
    line-height: 30px;
  }
}
.cancellationOrder {
  margin-top: 10px;
  color: #2b2b2b;
  font-size: 14px;
}
.typeItem {
  display: flex;
  .typeItem-Iss {
    width: 50%;
  }
  .typeIss {
    width: 330px;
    height: 135px;
    background: #fafafa;
    border-radius: 4px;
    border: 1px solid #d3dbeb;
    text-align: center;
    .typeIss-up {
      width: 208px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #2b2b2b;
      margin: 30px auto 0;
    }
    .typeIss-down {
      width: 208px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #c4c5c6;
      line-height: 16px;
      margin: auto;
    }
  }
}
.activeIss {
  background: #f4f7ff url("../../../../assets/images/rightUp.jpg") no-repeat top
    right !important;
  background-size: 34px 34px !important;
  border: 1px solid #1267fa !important;
}
</style>